import QtQuick 1.1
import com.meego 1.0
import "Modulelib.js" as ModuleUtil

ListModel {
    id: container

    function getData() {
        var doc = new XMLHttpRequest();
        doc.onreadystatechange = function() {
            if (doc.readyState == XMLHttpRequest.HEADERS_RECEIVED) {
            } else if (doc.readyState == XMLHttpRequest.DONE) {
                var a = doc.responseXML.documentElement;
                var letter = ""; var brandId = 0; var brandName = ""; var brandImage = ""; var brandLetter = "";
                 for (var i = 0; i < a.childNodes.length; ++i) {//节点<Rrands>
                    if(a.childNodes[i] !== null && a.childNodes[i].childNodes.length > 1){ // 去掉text节点
                        letter = a.childNodes[i].childNodes[1].childNodes[0].nodeValue; //节点<Letter>

//                        container.append({"Type":"letter","Letter":letter,"id":0,"name":"","img":"","FirstLetter":letter});
                        for(var ii = 1; ii < a.childNodes[i].childNodes.length; ++ii){//节点<Brand>
                            if(a.childNodes[i].childNodes[ii]!== null && a.childNodes[i].childNodes[ii].childNodes.length > 1){
                                brandId = a.childNodes[i].childNodes[ii].childNodes[1].childNodes[0].nodeValue;
                                brandName = a.childNodes[i].childNodes[ii].childNodes[3].childNodes[0].nodeValue;

                                brandImage = a.childNodes[i].childNodes[ii].childNodes[5].childNodes[0].nodeValue;
                                brandLetter = a.childNodes[i].childNodes[ii].childNodes[7].childNodes[0].nodeValue;
                                container.append({"Type":"item","Letter":letter,"id":brandId,"name":brandName,"img":brandImage,"FirstLetter":brandLetter});
                            }
                        }
                    }
            }
               modulelibs_page.busy = false;
            }
        }

        doc.open("GET", ModuleUtil.getModuleLibsUrl());
        doc.send();
    }
}
